package com.ruoyi.api.yh.blood;

import com.github.xiaoymin.knife4j.annotations.ApiOperationSupport;
import com.github.xiaoymin.knife4j.annotations.ApiSupport;
import com.ruoyi.api.yh.version.ApiVersion;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.yh.api.R;
import com.ruoyi.common.yh.api.dtovo.blood.ArticleInfoVO;
import com.ruoyi.common.yh.api.dtovo.blood.BloodImageVO;
import com.ruoyi.yh.domain.YhArticleInfo;
import com.ruoyi.yh.domain.YhBloodImage;
import com.ruoyi.yh.service.IYhArticleInfoService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.dozer.Mapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.ArrayList;
import java.util.List;

@ApiSupport(order = 0)
@Api(tags="文章")
@RestController
@ApiVersion(1)
@RequestMapping("/{version}/app-api/article")
public class YhArticleInfoApiController  extends BaseController {
    @Autowired
    private IYhArticleInfoService yhArticleInfoService;
    @Autowired
    private Mapper dozerMapper;
    /**
     *
     *
     */

    @ApiOperation("获取文章列表")
    @ApiOperationSupport(author = "cmm",order = 0)
    @RequestMapping(value = "/getArticleList",method = RequestMethod.GET)
    public R<List<ArticleInfoVO>> getArticleList(@ApiParam(name="articleType",value = "文章类型",required = true)@RequestParam String articleType,@ApiParam(name="searchInput",value = "文章类型",required = true)@RequestParam String searchInput)
    {
        YhArticleInfo yhArticleInfoquery=new YhArticleInfo();
        yhArticleInfoquery.setArticleType(articleType);
        yhArticleInfoquery.setArticleTitle(searchInput);
        List<YhArticleInfo> list = yhArticleInfoService.selectYhArticleInfoList(yhArticleInfoquery);
        List<ArticleInfoVO>  articleInfoVOs=new ArrayList<>();
        for(YhArticleInfo yhArticleInfo:list){
            ArticleInfoVO articleInfoVO=dozerMapper.map(yhArticleInfo, ArticleInfoVO.class);
            articleInfoVOs.add(articleInfoVO);
        }
        return R.ok(articleInfoVOs,"获取文章列表");
    }
    /**
     *
     *
     */

    @ApiOperation("获取文章详情")
    @ApiOperationSupport(author = "cmm",order = 0)
    @RequestMapping(value = "/getArticleById",method = RequestMethod.GET)
    public R<ArticleInfoVO> getArticleById(@ApiParam(name="articleId",value = "文章id",required = true)@RequestParam Long articleId)
    {

        YhArticleInfo yhArticleInfo= yhArticleInfoService.selectYhArticleInfoByArticleId(articleId);
        ArticleInfoVO articleInfoVO=dozerMapper.map(yhArticleInfo, ArticleInfoVO.class);
        if(yhArticleInfo.getArticleBrowse()==null){
            yhArticleInfo.setArticleBrowse(1L);
        }else{
            yhArticleInfo.setArticleBrowse(yhArticleInfo.getArticleBrowse()+1L);
        }
        if(yhArticleInfo.getArticleContent()!=null){

        }
        yhArticleInfoService.updateYhArticleInfo(yhArticleInfo);
        articleInfoVO.setArticleContent(articleInfoVO.getArticleContent().replaceAll("/prod-api","http://124.221.32.150:8980/wx-api"));
        return R.ok(articleInfoVO,"获取文章详情");
    }
}
